package com.un.ebs.contract.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.un.ebs.contract.domain.*;
import com.un.ebs.contract.dto.*;
import com.un.ebs.contract.enums.ContractTypeEnum;
import com.un.ebs.inventory.enums.BusinessRelationTypeEnum;
import com.un.ebs.sale.dto.SaleOrderItemDto;

import java.math.BigDecimal;
import java.util.List;

/**
 * (Contract)表服务接口
 *
 * @author liubo
 * @since 2020-07-05 18:05:55
 */
public interface ContractService extends IService<Contract> {

    /**
     * 合同创建
     *
     * @param req
     * @return
     */
    String add(ContractDto req);

    /**
     * 根据采购订单生成采购合同
     *
     * @param req
     */
    void addByPurchaseOrder(PurchaseOrderToContractDto req);

    /**
     * 根据合同生成入库单
     *
     * @param id
     */
    void createOemBomInventoryInNote(String id, String noteTypeId, String warehouseId);

    /**
     * 合同修改
     *
     * @param req
     */
    void update(ContractDto req);

    void update(List<ContractDto> reqs);

    /**
     * 合同删除
     *
     * @param id
     */
    void delete(String id);

    void deleteItemById(String id);

    /**
     * 合同变更
     *
     * @param req
     */
    String change(ContractChangeDto req);

    /**
     * 复制为正式合同
     *
     * @param id
     */
    void copyToFormal(String id);

    /**
     * 合同提交
     *
     * @param id
     */
    void submit(String id);

    /**
     * 合同撤销
     *
     * @param id
     */
    void submitCancel(String id);

    /**
     * 合同审核
     *
     * @param id
     */
    void audit(String id);

    /**
     * 审核撤销
     *
     * @param id
     */
    void auditCancel(String id);

    void close(String id);

    /**
     * 合同关闭并派生子合同
     *
     * @param req
     */
    void closeAndDerive(ContractCloseAndDeriveDto req);

//    /**
//     * 临时合同核销
//     * @param req
//     */
    //void writeOff(ContractWriteOffDto req);

    void writeOff(String tempContractItemId, String formalContractId, double qty);

    void writeOffCancel(String id);

    void writeOffUpdate(String id, double qty);

    List<String> queryPersonUserIds(String entId);

    List<ContractItemWriteOffView> queryWriteOffView(String skuId, String tempContractCode, String formalContractCode);

    IPage<ContractTempNotWriteOffExt> queryNotWriteOffByCustomer(String skuCode,String customerId, int pageSize, int pageIndex);

    List<BusinessEntDto> queryBusinessEnt();

    List<BusinessEntDto> queryBusinessEnt(BusinessRelationTypeEnum type);

    List<BusinessEntDto> queryBusinessEntBySaleFormalContract();

    IPage<ContractExt> querySaleFormal(String customerEntId, int pageSize, int pageIndex);

    List<ContractItemChangeInfo> queryChange(String contractCode, int oldVer, int newVer);

    Contract queryById(String id);

    ContractVo queryViewById(String id);

    ContractVo queryViewByCode(String code);

    ContractVo queryViewByEnt(String entId);

    /***
     * 剩余需要执行的合同量
     * @param contractId
     * @return
     */
    //List<SaleOrderItemDto> queryNotRunContractItem(String contractId);

    ContractItemExt queryPurchasePrice(String entId,String skuId);

    List<ContractItemExt> queryPurchasePriceList(String skuId);

    ContractItemExt querySalePrice(String entId, String skuId);

    ContractItemExt querySalePriceBySkuCode(String entId,String skuCode);

    List<ContractItemExt> querySalePriceBySkuCode(String skuCode);

    ContractVo queryPurchaseFrame(String entId);

    double queryCustomerBalance(String entId);

    double querySupplierBalance(String entId);

    ContractVo queryPurchaseFrame(String entId, String skuId);

    void workflowPass(String id, String workflowInstanceId);

    List<ContractItemExt> queryItemsById(String id);

    List<ContractItemExt> queryItemById(String id, String classId);

    IPage<ContractItemExt> queryItemBySku(String skuId, int pageSize, int pageIndex);

    IPage<ContractItemExt> queryItemByCode(String code, int pageSize, int pageIndex);

    IPage<ContractExt> query(String searchText, ContractTypeEnum type, Boolean frameStatus, String entId, int pageSize, int pageIndex);

    /**
     * 合同比例分配，一般指采购比例
     *
     * @param req
     */
    void assignSupplyPercent(ContractSupplyPercentAssignDto req);

    IPage<SaleContractExt> querySaleContract(String searchText, ContractTypeEnum type, String customerId, String personnelId, String skuId, int pageSize, int pageIndex);

    List<SaleContractExt> querySaleContract(String contractCode);

    IPage<SaleContractByCustomerExt> querySaleContractByCustomer(String searchText, String customerId, int pageSize, int pageIndex);

    IPage<ContractItemExt> queryItemByFrameAndEnt(String searchText, String entId, int pageSize, int pageIndex);

    IPage<ContractItemBySaleExt> queryItemBySale(String searchText, String entId, int pageSize, int pageIndex);

//    IPage<QualityContractItemExt> queryItemByQuality(String skuCode, String entId, int pageSize, int pageIndex);

    IPage<ContractItemWriteOffDetailExt> queryWriteOffDetail(String searchText, int pageSize, int pageIndex);

    List<ContractItemWriteOffDetailExt> queryWriteOffDetailByTemporaryContractCode(String temporaryContractCode, String[] skuCodes);

    IPage<ContractExt> querySaleCanInvoice(String searchText, int pageSize, int pageIndex);

    List<ContractItemRunDto> querySaleContractRunItem(String contractCode, String skuCode);
}